<template>
	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
		
	  <el-form-item label="供应商名称" prop="sname" >
	    <el-input v-model="ruleForm.sname"></el-input>
	  </el-form-item>
	  <el-form-item label="供应商简称" prop="sabbreviation" >
	    <el-input v-model="ruleForm.sabbreviation"></el-input>
	  </el-form-item>
	  <el-form-item label="地址" prop="saddress" >
	    <el-input v-model="ruleForm.saddress"></el-input>
	  </el-form-item>
	  <el-form-item label="公司电话" prop="sphone1" >
	    <el-input v-model="ruleForm.sphone1"></el-input>
	  </el-form-item>
	  <el-form-item label="邮件" prop="semail" >
	    <el-input v-model="ruleForm.semail"></el-input>
	  </el-form-item>
	  <el-form-item label="联系人" prop="scontact" >
	    <el-input v-model="ruleForm.scontact"></el-input>
	  </el-form-item>
	  <el-form-item label="联系人电话" prop="sphone2" >
	    <el-input v-model="ruleForm.sphone2"></el-input>
	  </el-form-item>
	  <el-form-item label="备注" prop="sremarks" >
	    <el-input v-model="ruleForm.sremarks"></el-input>
	  </el-form-item>
	 
	 
	  <el-form-item>
	    <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
	    <el-button @click="resetForm('ruleForm')">重置</el-button>
	  </el-form-item>
	</el-form>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          sname: '',
          sabbreviation: '',
		  saddress: '',
		  sphone1: '',
		  semail: '',
		  scontact: '',
		  sphone2: '',
		  sremarks: ''
        },
        rules: {
          sname: [
            { required: true, message: '请输入供应商名称', trigger: 'blur' },
          ],
          sabbreviation: [
            { required: true, message: '请输入供应商简称', trigger: 'blur' },
          ],
		  saddress: [
		    { required: true, message: '请输入地址', trigger: 'blur' },
		  ],
		  sphone1: [
		    { required: true, message: '请输入公司电话', trigger: 'blur' },
		  ],
		  semail: [
		    { required: true, message: '请输入邮件', trigger: 'blur' },
		  ],
		  scontact: [
		    { required: true, message: '请输入联系人', trigger: 'blur' },
		  ],
		  sphone2: [
		    { required: true, message: '请输入联系人电话', trigger: 'blur' },
		  ],
		  sremarks: [
		    { required: true, message: '请输入备注', trigger: 'blur' },
		  ]
        }
      };
    },
    methods: {
      submitForm(formName) {
		  const _this=this
          this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.post('http://localhost:8181/supplier/addSupplier',this.ruleForm).then(function(resp){
				console.log(resp)
				if(resp.data == 'sucess'){
					alert('添加成功')
					_this.$router.push('/SupplierManage')
				}
			})
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>


